package com.jingtai.validate.controller;

import com.jingtai.validate.bean.DataVo;
import com.jingtai.validate.swagger.CApiParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiSort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = "4.Swagger&Jsr303片定义Valid测试", tags = { "Swagger&Jsr303片定义Valid测试接口" })
@ApiSort(value = 4)
@Validated
@RestController
@RequestMapping("capivalidate")
public class CApiValidateController {

	@GetMapping("/params")
	public ResponseEntity<DataVo<Object[]>> get(
			@CApiParam(name = "nullEmptyCheck", value = "空值测试字段", required = false, message = "测试字段", cNotEmpty = false) @RequestParam("nullEmptyCheck") String nullEmptyCheck,
			@CApiParam(name = "email", value = "邮件", required = true, defaultValue = "email@123.com", message = "ID", cEmail = true, cPhone = false) @RequestParam("email") String email,
			@CApiParam(name = "age", value = "年龄value", required = true, defaultValue = "18", message = "年龄", cIntMin = 1, cIntMax = 250) @RequestParam("age") int age,
			@Valid @CApiParam(name = "phone", value = "手机号", required = true, defaultValue = "1336824158", message = "手机", cStrMinLen = 5, cStrMaxLen = 20, cPhone = true) @RequestParam("phone") String phone) {
		return ResponseEntity.ok(new DataVo<Object[]>(HttpStatus.OK).message("请求成功")
				.data(new Object[] { email, age, nullEmptyCheck, phone }));
	}

}
